<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-1-20
 * Time: 下午3:52
 */
include("/var/www/html/alipay/lib/alipay_notify.class.php");
include '/var/www/html/new/com.inc.php';
include("/var/www/html/new/d/class/SoapInit.class.php");
define('LOG_NAME', '/var/www/html/new/d/module/alipay_refund/log_' . date('Ymd').'.txt');
define('ACTION_MONEY_ADD',0);
define('ACTION_MONEY_CUT',1);
function write_logs($txt,$file='/var/www/html/new/d/module/alipay_refund/log.txt'){
    $fp = fopen($file,"a");
    flock($fp, LOCK_EX);
    fwrite($fp,date("Y-m-d H:i:s").":".$txt."\n");
    flock($fp, LOCK_UN);
    fclose($fp);
}

$ordernum = 686394;
$total_fee = 3;
//TODO::上级供应商扣钱
$soap = new SoapClient(null,array(
        "location" => "http://localhost/open/openService/pft_insideMX.php",
        "uri" => "www.16u.com?ac_16u=16ucom|pw_16u=c33367701511b4f6020ec61ded352059|auth_16u=true")
);
$xml  = $soap->Order_Globle_Search("", "", "", "", "", "", "", "", "", "", "", "",
    $ordernum, "", "", "", "", "", "", "1", "0", "100", "0", "0",
    "", "0", "", "0", "", "", "", "0", "0");
//echo $xml;Response;
$order_arr = simplexml_load_string($xml);
//print_r($order_arr);Response;
if (!count($order_arr)) {
    write_logs("[{$ordernum}]|订单号不能为空",LOG_NAME);
}
//TODO::上级扣钱
$mid_not_cut = array(7517,7133,7134,7135,7136,);//鼓浪屿，云顶的供应商ID
$aid         = (int)$order_arr->Rec->UUaid;
$mid         = (int)$order_arr->Rec->UUmid;
echo $mid,'----';
if ( !in_array( $aid, $mid_not_cut )) {
    $remotenum = (string)$order_arr->Rec->UUremotenum;
    $orderMode = 0;
    $cut_mid   = $aid;
    echo $remotenum,'----';
    //TODO::根据远端订单号判断是否为散客下单。
    if ( strpos($remotenum, '_')!==false) {
        $remote_arr = explode('_', $remotenum);
        print_r($remote_arr);
        if ($remote_arr[3]=='SK') {
            echo '---',$remote_arr[3],'----';
            $cut_mid = $mid;
        }
    }
//        $res = $soap->PFT_Member_Fund_Modify($cut_mid, 0 , $total_fee, ACTION_MONEY_CUT, 0,null,0, 0,$ordernum);
    echo "上级供应商扣钱:$cut_mid, 0 , $total_fee, ACTION_MONEY_CUT, 0,null,0, 0,$ordernum";
}

$sql = "UPDATE pft_alipay_rec SET status=2 WHERE trade_no='$trade_no' LIMIT 1";
echo $sql;
//            write_logs("sql4:" . $sql);
//    $GLOBALS['le']->query($sql);
    //添加交易记录

    //交易记录
    $str="INSERT INTO pft_member_alipay SET fid={$refund_data['aid']},"
        ."total_fee=$total_fee,orderid='$ordernum',money=$total_fee,"
        ."daction=1,dtype=1,rectime=now(),ali_account=''";
//            $GLOBALS['le']->query($str);
    //$GLOBALS['le']->query($str);
